<?php
declare (strict_types = 1);

namespace app\common\listener;

use think\swoole\Websocket;

class SubTest
{
    protected  $websocket = null;


    public function __construct(\think\Container $container)
    {
        //$this->websocket = app('think\swoole\Websocket');
        $this->websocket = $container->make(Websocket::class);
    }
    // 连接事件
    public function onConnect()
    {
        //var_dump($this->websocket->getSender());
        $this->websocket->emit('sendfd', $this->websocket->getSender());
    }
    // 加入房间
    public function onJoin($event)
    {
       /* $ws = app('think\swoole\Websocket');
        //
        $roomobj = app('think\swoole\websocket\Room');

        $this->websocket->join($event['room']);

        // 获取指定房间下有哪些客户端
        var_dump($roomobj->getClients($event['room']));
        // 获取指定客户端加入了哪些房间
        var_dump($roomobj->getRooms($ws->getSender()));*/
        $this->websocket->emit('joincallback', '房间加入成功');
    }

    // “弹幕”房间消息发送
    public function onRoomTest($event)
    {
        //var_dump($event);
        $this->websocket->to($event['room'])->emit('roomtestcallback', $event['message']);
    }


}
